//
//  LGHomeHeaderView.m
//  ligenyun
//
//  Created by apple on 2018/3/23.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGHomeHeaderView.h"

@interface LGHomeHeaderView()
@property(nonatomic, strong) STAdvertingScrollView     *adverView;
@end
@implementation LGHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --SubView
- (void)configSubView{
    __weak typeof(self) weakSelf = self;
    self.adverView = [[STAdvertingScrollView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 156) andWithArray:@[@"首页banner"] handle:^(NSInteger num) {
        if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(onslectedBannerWithIndex:)]) {
            [weakSelf.delegate onslectedBannerWithIndex:num];
        }
    }];
    self.adverView.pageControll.bottom = self.adverView.height - 15;
    self.adverView.pageControll.currentPageIndicatorTintColor = [UIColor whiteColor];
    self.adverView.pageControll.pageIndicatorTintColor = FirstTextColor;
    self.adverView.pageControll.hidden = YES;
    self.adverView.pageControll.centerX = UIScreenWidth / 2;
    self.adverView.canAutoScroll = NO;
    [self addSubview:self.adverView];
    

    NSArray * array = @[@{@"title":@"私祭",@"imageName":@"私祭"},
                        @{@"title":@"公祭",@"imageName":@"公祭"},
                        @{@"title":@"祠堂",@"imageName":@"祠堂"},
                        @{@"title":@"礼根文化",@"imageName":@"礼根文化"},
                        @{@"title":@"寻根",@"imageName":@"寻根"},
                        @{@"title":@"家谱",@"imageName":@"家谱"},
                        @{@"title":@"家庭树",@"imageName":@"家庭树"},
                        @{@"title":@"陵园墓地",@"imageName":@"陵园墓地"},
                        @{@"title":@"今日祭祀",@"imageName":@"今日祭祀"}
                        ];
    CGFloat controlWith = UIScreenWidth / 4;
    CGFloat top = 0;
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.adverView.bottom, UIScreenWidth, controlWith * 3)];
    self.height = imageView.bottom;
    imageView.userInteractionEnabled = YES;
    imageView.image = [UIImage imageNamed:@"首页bg"];
    [self addSubview:imageView];
    for (NSInteger i = 0 ; i < array.count;i ++) {
        NSDictionary * dic = array[i];
        NSString * imageName = dic[@"imageName"];
        NSString * title = dic[@"title"];
        STButton * namButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, controlWith, controlWith)
                                                          title:nil
                                                     titleColor:nil
                                                      titleFont:0
                                                   cornerRadius:0
                                                backgroundColor:nil
                                                backgroundImage:nil
                                                          image:[UIImage imageNamed:imageName]];
        [namButton setClicAction:^(UIButton *sender) {
            if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(onslectedResbonderWithTitle:)]) {
                [weakSelf.delegate onslectedResbonderWithTitle:title];
            }
        }];
        namButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [imageView addSubview:namButton];
        
        namButton.left = (i%4) * controlWith;
        namButton.top = (i/4) * controlWith + top;
        //top = menu.bottom;

    }

}
@end
